<?php
/*
 *   This file is part of Verbum.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *   Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */ 

$_log->debug($op);
switch ($op) {
	case "lang":
		//out(jsonList($LANGUAGE_LIST,array("name","value")));
		out(jsonList(loadLanguageList(),array("lang","name")));		
		break;
	
	case "timezone":
		out(jsonList($TIMEZONE_LIST,array("name","value")));	
		break;
		
	case "team":
		$team = new team;
		$team->status=STATUS_ACTIVE;
		$list = $loader->loadListBy($team,$team->listByStatus());
		out(jsonList($list,array("id","name")));
		break;
		
	case "prjlt":
		$prj = new project;
		$prj->status=STATUS_ACTIVE;
		$list = $loader->loadListBy($prj,$prj->listByStatus());
	
		if ($CURRENT_USER->groupid == GROUP_ADMIN) {
			$slist = $list;
		} else {
			$slist = array();
			foreach ($list as $obj) {
				$file = new files($obj->id);
				$file->teamid=getTeamId($CURRENT_USER);
				$i = $loader->fetchcount($file->countTeam());
				if ($i>0) {
					array_push($slist,$obj);
				}
			}
		}
		out(jsonList($slist,array("id","name","statsupdated")));	
		break;

	case "sprj":
		$prj = new project;
		$prj->status=STATUS_ACTIVE;
		$prj->parent=$param['id'];
		$list = $loader->loadListBy($prj,$prj->listByAny());
		out(jsonList($list,array("id","name","statsupdated")));		
		break;		
	case "status":
		out(jsonList($FILE_STATUS_LIST,array("id")));
		break;

	case "assign_trans":
		$flist = array();	
		array_push($flist,array("id"=>FILE_STATUS_TRANS));
		array_push($flist,array("id"=>FILE_STATUS_CHKPND));
		array_push($flist,array("id"=>FILE_STATUS_LOCKED));
		out(jsonList($flist,array("id")));	
		break;

	case "assign_rev":
		$flist = array();
		array_push($flist,array("id"=>FILE_STATUS_PROOF));
		array_push($flist,array("id"=>FILE_STATUS_DONE));	
		array_push($flist,array("id"=>FILE_STATUS_CHKPND));
		out(jsonList($flist,array("id")));
		break;

	case "assign_coord":
		$flist = array();
		array_push($flist,array("id"=>FILE_STATUS_TODO));
		array_push($flist,array("id"=>FILE_STATUS_LOCKED));
		array_push($flist,array("id"=>FILE_STATUS_TRANS));
		array_push($flist,array("id"=>FILE_STATUS_CHKPND));
		array_push($flist,array("id"=>FILE_STATUS_PROOF));
		array_push($flist,array("id"=>FILE_STATUS_DONE));	
		out(jsonList($flist,array("id")));
		break;

	case "user":
		$u = new user;
		$u->teamid = getTeamId($CURRENT_USER);
		$u->status = STATUS_ACTIVE;
		$list = $loader->loadListBy($u,$u->simpleListByFilters());
		$llist = array();
		array_push($llist,array("userid" => s("< Clear current assignment >"), "value" => "none" ));
		foreach ($list as $u) {
			$v = array();
			$v['userid']=$u->userid;
			$v['value']=$u->userid;
			array_push($llist,$v);
		}
		out(jsonList($llist,array("userid","value")));	
		break;
	
	case "stats":
		$file = new files($param['pid']);
		$file->teamid=getTeamId($CURRENT_USER);
		$list = $loader->loadListBy($file,$file->getStats());
		out(jsonList($list,array("translated","untranslated","fuzzy")));
		break;
	default:
		failed(s("Unrecognized command"));
		break;
}
 
?>

 